package org.example.cake.service.impl;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;



import org.springframework.stereotype.Service;
import org.example.cake.mapper.AddressMapper;
import org.example.cake.entity.Address;
import org.example.cake.service.AddressService;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService{

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public int deleteByPrimaryKey(Integer addressid) {
        return addressMapper.deleteByPrimaryKey(addressid);
    }

    @Override
    public int insert(Address record) {
        return addressMapper.insert(record);
    }

    @Override
    public int insertSelective(Address record) {
        return addressMapper.insertSelective(record);
    }

    @Override
    public Address selectByPrimaryKey(Integer addressid) {
        return addressMapper.selectByPrimaryKey(addressid);
    }

    @Override
    public int updateByPrimaryKeySelective(Address record) {
        return addressMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Address record) {
        return addressMapper.updateByPrimaryKey(record);
    }

    /**
     * 根据用户id查询收货地址
     * @param userid 用户id
     * @return 地址集合
     */
    public List<Address> selectAddressByUserid(@Param("userid") Integer userid){
        return addressMapper.selectAddressByUserid(userid);
    }
    /**
     * 根据地址id查询地址详情
     * @param addressid 地址id
     * @return 地址实体
     */
    public Address selectAddressById(@Param("addressid") Integer addressid){
        return addressMapper.selectAddressById(addressid);
    }
    /**
     * 修改地址
     * @param address 地址实体
     * @return 收影响的行数
     */
    public int updateAddress(Address address){
        return addressMapper.updateAddress(address);
    }
    /**
     * 新增地址
     * @param address 地址对象
     * @return 收影响的行数
     */
    public int insertAddress(Address address){
        return addressMapper.insertAddress(address);
    }
    /**
     * 根据地址id删除地址
     * @param addressid 地址id
     * @return 受影响的行数
     */
    public int deleteAddressById(@Param("addressid") Integer addressid){
        return addressMapper.deleteAddressById(addressid);
    }

    @Override
    public List<Address> selectAllAddresss(String consignee, String phone, String province, String city, String district) {
        return addressMapper.selectAllAddresss(consignee,phone,province,city,district);
    }

    @Override
    public Address getById(Integer addressid) {
        return addressMapper.selectByPrimaryKey(addressid);
    }

    /**
     * 修改默认地址
     * @param defaultaddress 默认地址 0：默认 1：不默认
     * @param addressid 地址id
     * @return 受影响的行数
     */
    public int updateDefaultAddress(@Param("defaultaddress") Integer defaultaddress,@Param("addressid") Integer addressid){
        return addressMapper.updateDefaultAddress(defaultaddress,addressid);
    }
}
